package gui;

/**
 * @author Wray
 */

import shop.Main;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;



public class MenuGui {
    public MenuGui() {
        initMenuGui();
    }
    //菜单GUI
    public void initMenuGui() {

//        Mall mall=new Mall();//新建商城
//        Mall.importMall1(mall.getProlist());//导入商城1的商品信息



//        OrderGui ordergui=new OrderGui();//新建订单界面
//        ShoppingCartFrame shoppingcartgui= new ShoppingCartFrame(ordergui);//新建购物车界面
//        ProductListFrame productlistgui=new ProductListFrame(shoppingcartgui,mall);//新建商品列表界面
//        SearchGui search=new SearchGui(shoppingcartgui,mall);//新建搜索界面


        JFrame menu = new JFrame("菜单");

        menu.setLayout(null); // 清除布局函数
        menu.setResizable(false); // 设置窗体大小不可变
        menu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        menu.setLayout(new BorderLayout()); // 新建BorderLayout布局

        // 欢迎语
        JPanel titlePanel = new JPanel(new FlowLayout());
        JLabel titleLabel = new JLabel("购物系统菜单");
        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 30)); // 设置字体、样式、大小
        titlePanel.add(titleLabel);
        titlePanel.setBorder(new EmptyBorder(10, 10, 0, 10));
        menu.add(titlePanel, BorderLayout.NORTH);

        // 菜单按钮
        JPanel menuPanel = new JPanel(new GridLayout(5, 1));
        JButton mallButton = new JButton("商城");
        mallButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MallGui mallGui=new MallGui();
                mallGui.mallGui.setVisible(true);
            }
        });

//        JButton jb2 = new JButton("查找商品");
//        jb2.addActionListener(new java.awt.event.ActionListener() {
//            @Override
//            public void actionPerformed(java.awt.event.ActionEvent evt) {
//                search.searchGui.setVisible(true);
//            }
//        });

        JButton shoppingCartButton = new JButton("我的购物车");
        shoppingCartButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ShoppingCartGui shoppingCartGui=new ShoppingCartGui(Main.person.shoppingCart);
                shoppingCartGui.shoppingCartGui.setVisible(true);
            }
        });

//        JButton jb4 = new JButton("查看订单");
//        jb4.addActionListener(new java.awt.event.ActionListener() {
//            public void actionPerformed(java.awt.event.ActionEvent evt) {
//                ordergui.getOrderGui().setVisible(true);
//            }
//        });

        JButton exitButton = new JButton("退出");
        exitButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                System.exit(0);
            }
        });

        int w = 10;
        int h = 50;
        mallButton.setPreferredSize(new Dimension(w, h));
        //jb2.setPreferredSize(new Dimension(w, h));
        shoppingCartButton.setPreferredSize(new Dimension(w, h));
       // jb4.setPreferredSize(new Dimension(w, h));
        exitButton.setPreferredSize(new Dimension(w, h));

        mallButton.setFont(new java.awt.Font("黑体", 1, 20));
       // jb2.setFont(new java.awt.Font("黑体", 1, 20));
        shoppingCartButton.setFont(new java.awt.Font("黑体", 1, 20));
       // jb4.setFont(new java.awt.Font("黑体", 1, 20));
        exitButton.setFont(new java.awt.Font("黑体", 1, 20));

        menuPanel.add(mallButton);
      //  menuPanel.add(jb2);
        menuPanel.add(shoppingCartButton);
       // menuPanel.add(jb4);
        menuPanel.add(exitButton);

        menuPanel.setBorder(new EmptyBorder(20, 20, 20, 20));
        menu.add(menuPanel);


        // Display the window.
        menu.pack();
        menu.setVisible(true);
        // 设置窗口居中显示
        SettingWindow.setFrameCenter(menu);
    }

}
